* prep 3 * prepare BESIP data
	
clear all	 
set maxvar 10000
	 
cd "$data"
use "BES2019_W23_Panel_v23.0.dta", clear 

keep id cutsTooFarNHSW* cutsTooFarNationalW* cutsTooFarLocalW* enviroGrowthW* EUIntegrationSelfW* redistSelfW* immigEconW* immigCulturalW* immigSelfW* leftRightW* p_turnout_2005 p_turnout_2010 p_turnout_2015 p_turnout_2017 p_turnout_2019 countryW* likeLabW* likeConW* likeLDW* likeSNPW* likePCW* likeBrexitPartyW* p_educationW20 gender ageW20 p_gross_personalW20 workingStatusW20 subjClassW20 p_eurefturnout partyIdW20 taxSpendSelfW* taxHighIncomeW15 taxMiddleIncomeW15 taxLowIncomeW15 Age eesEUIntegrationSelfW*


gen higheducation = .
replace higheducation = 1 if p_educationW20==15 | p_educationW20==16 | p_educationW20==17 | p_educationW20==18 
replace higheducation = 0 if p_educationW20>0 & p_educationW20<15

gen female = .
replace female = 1 if gender==2 
replace female = 0 if gender==1 

gen age = ageW20

gen highincome = .
replace highincome = 1 if p_gross_personalW20>5 & p_gross_personalW20<15
replace highincome = 0 if p_gross_personalW20>0 & p_gross_personalW20<6

gen employment = .
replace employment = 0 if workingStatusW20==4 | workingStatusW20== 9 | workingStatusW20==10 | workingStatusW20==9 // unemployed, not in paid work, furloughed, other 
replace employment = 1 if workingStatusW20==1 | workingStatusW20==2 | workingStatusW20==3 | workingStatusW20==5 | workingStatusW20==6 // working, student
replace employment = 2 if workingStatusW20==7 // retired 



 recode likeLabW* (9999=.)
 recode likeConW* (9999=.)
 recode likeLDW* (9999=.)
 recode likeSNPW* (9999=.)
 recode likePCW* (9999=.)
 recode likeBrexitPartyW* (9999=.)
 
 gen partisan = .
 replace partisan = 1 if partyIdW20==1 | partyIdW20==2 | partyIdW20==3 | partyIdW20==4 | partyIdW20==5 | partyIdW20==7 | partyIdW20==9 | partyIdW20==12 
 replace partisan = 0 if partyIdW20==10 | partyIdW20==9999
 
 
 /*
	* Attitudes and Preferences 
	
	
	*cuts to NHS has gone too far (cutsTooFarNHSW*)	
	recode cutsTooFarNHSW* (9999=.)

	*cuts to public spending (national) gone too far (cutsTooFarNationalW*)
	recode cutsTooFarNationalW* (9999=.)
	
	*cuts to local services gone too far (cutsTooFarLocalW*)
	recode cutsTooFarLocalW* (9999=.)
	
	*environment should have priority (10-protect the environment, 0-economic growth)
	recode enviroGrowthW* (9999=.)
	
	*EU Integration (0-unite fully, 10-protect our independence)
	recode EUIntegrationSelfW* (9999=.)
	
	*redistribution (0-make incomes more equal, 10- gov should be less concerned)
	recode redistSelfW* (9999=.)
	
	*immigration economic (1-bad for economy, 7-good for economy)
	recode immigEconW* (9999=.)
	
	*immigration cultural (1-undermines cultural life, 7-enriches cultural life)
	recode immigCulturalW* (9999=.)
	
	*immigration: allow more or less? (0-fewer, 10-more)
	recode immigSelfW* (9999=.)
	
	*leftright
	recode leftRightW* (9999=.)
	
*/	
	* Turnout
	
	*p_turnout_2005
	*p_turnout_2010 
	*p_turnout_2015 
	*p_turnout_2017 
	*p_turnout_2019 
	
	recode p_turnout_2005 (9999=.)
	recode p_turnout_2010 (9999=.)
	recode p_turnout_2015 (9999=.)
	recode p_turnout_2017 (9999=.)
	recode p_turnout_2019 (9999=.)
	
	recode p_turnout_2005 (.=1000)
	recode p_turnout_2010 (.=1000)
	recode p_turnout_2015 (.=1000)
	recode p_turnout_2017 (.=1000)
	recode p_turnout_2019 (.=1000)

	egen totalturnout = rowtotal(p_turnout_2015 p_turnout_2017 p_turnout_2019)
	egen totalturnout2 = rowtotal(p_turnout_2010 p_turnout_2015 p_turnout_2017 p_turnout_2019)

	
	gen votertype = .
	replace votertype = 0 if totalturnout==0 // perpetual non-voter
	replace votertype = 1 if totalturnout==1 | totalturnout==2 // peripheral voter
	replace votertype = 2 if totalturnout==3  // always voter

	label define votertypelabels 0"perpetual non-voter" 1"peripheral voter" 2"regular voter"
	label values votertype votertypelabels
	
	gen votertype2 = .
	replace votertype2 = 0 if totalturnout2==0 // perpetual non-voter
	replace votertype2 = 1 if totalturnout2==1 | totalturnout2==2  | totalturnout2==3 // peripheral voter
	replace votertype2 = 2 if totalturnout2==4  // always voter

	
	*first focus on 2015, 2017 and 2019 in order not to lose too many observations. Then you can also look at 2010 and 2005 turnout
	
	
	
	
	* Alienation: R has at least 1 political party that they like (>5) or not?
	
	gen likeLabour19 = 1 if likeLabW19>5 & likeLabW19<11
		replace likeLabour19 = 0 if likeLabW19<6 & likeLabW19>-1
		replace likeLabour19 = 1000 if likeLabW19==.
	gen likeCon19 = 1 if likeConW19>5 & likeConW19<11
		replace likeCon19 = 0 if likeConW19<6 & likeConW19>-1
		replace likeCon19 = 1000 if likeConW19==.
	gen likeLD19 = 1 if likeLDW19>5 & likeLDW19<11
		replace likeLD19 = 0 if likeLDW19<6 & likeLDW19>-1
		replace likeLD19 = 1000 if likeLDW19==.
	gen likeSNP19 = 1 if likeSNPW19>5 & likeSNPW19<11
		replace likeSNP19 = 0 if likeSNPW19<6 & likeSNPW19>-1
		replace likeSNP19 = 1000 if likeSNPW19==.
	gen likePC19 = 1 if likePCW19>5 & likePCW19<11
		replace likePC19 = 0 if likePCW19<6 & likePCW19>-1
		replace likePC19 = 1000 if likePCW19==.
	gen likeBrexit19 = 1 if likeBrexitPartyW19>5 & likeBrexitPartyW19<11
		replace likeBrexit19 = 0 if likeBrexitPartyW19<6 & likeBrexitPartyW19>-1
		replace likeBrexit19 = 1000 if likeBrexitPartyW19==.

	
		egen total_likes = rowtotal(likeLabour19 likeCon19 likeLD19 likeSNP19 likePC19 likeBrexit19)

		gen alienated = 0
		replace alienated = 1 if total_likes==0 | total_likes==1000 | total_likes==2000 | total_likes==3000 | total_likes==4000 | total_likes==5000 
		replace alienated = . if total_likes==6000 

		
	gen samplelimit = 1 if leftRightW20!=. & immigSelfW20!=. & immigEconW20!=. & immigCulturalW20!=. & redistSelfW20!=. & EUIntegrationSelfW20!=. & enviroGrowthW20!=. & taxSpendSelfW20!=.
	
	recode immigSelfW20 (0=10) (1=9) (2=8) (3=7) (4=6) (6=4) (7=3) (8=2) (9=1) (10=0)
	recode immigEconW20 (1=7) (2=6) (3=5) (5=3) (6=2) (7=1)
	recode immigCulturalW20 (1=7) (2=6) (3=5) (5=3) (6=2) (7=1)
	recode taxSpendSelfW20 (0=10) (1=9) (2=8) (3=7) (4=6) (6=4) (7=3) (8=2) (9=1) (10=0)
	recode enviroGrowthW20 (0=10) (1=9) (2=8) (3=7) (4=6) (6=4) (7=3) (8=2) (9=1) (10=0)
	
	
	
save "besip.dta", replace 
